/*
 * @(#)TestSuite.java
 *
 * Revision:
 * Author                                         Date           
 * --------------------------------------------   ------------   
 *  Jeremias D. Serafim de Araujo                     14/11/2012    
 */

package br.edu.ufcg.splab.generator;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import br.edu.ufcg.splab.core.InterfaceEdge;

/**
 * 
 * A class that represents a test suite, 
 * a Test Suite is a list of Test Cases. 
 * TestCase is a ArrayList of Edges
 * 
 * 
 */
public class TestSuite implements Collection<TestCase>{
   
   
	
	/**
	 * testSuite is a list of TestCases
	 */
    private List<TestCase> testSuite;
   
   
    public TestSuite(){
        this.testSuite = new ArrayList<TestCase>();
    }
   
    
    /**
     * 
     * Appends the testeCase in testSuite
     * @param path the path represents the test case and is a list of edges.
     */

	public void addTestCase(ArrayList<InterfaceEdge> path) {
		TestCase t = new TestCase(path);
		this.testSuite.add(t);
		
	}

	/**
	 * Appends the testCase in this testSuite
	 */
	
    @Override
    public boolean add(TestCase path) {
        return this.testSuite.add(path);
    }

    /**
     * Appends all of the testeCase in the testSuite
     */
    
    @Override
    public boolean addAll(Collection<? extends TestCase> arg0) {
        return this.testSuite.addAll(arg0);
    }

    /**
     * Remove all testeCases
     */
    
    @Override
    public void clear() {
        this.testSuite.clear();
    }

    /**
     * Checks if this testSuite contains the specified testeCase
     * @return true if this list contains all of the elements of the specified collection  
     */
    @Override
    public boolean contains(Object arg0) {
            return this.testSuite.contains(arg0);
    }

    /**
     * Return true is this testSuite contains all elements
     */
    
    @Override
    public boolean containsAll(Collection<?> arg0) {
            return this.testSuite.containsAll(arg0);
    }

    /**
     * 
     * Checks if the testeSuite is empty
     */
    
    @Override
    public boolean isEmpty() {
        return this.testSuite.isEmpty();
    }

    
    /**
     * 
     * Create a iterator of of a list of testCases
     * @return iterator an iterator over the elements in this list in proper sequence
     */
    @Override
    public Iterator<TestCase> iterator() {
        Iterator<TestCase> it = this.testSuite.iterator();
        return it;
    }

    
    /**
     * 
     * Remove element in this index
     * @param index position of element to remove
     */
    public void remove(int index) {
            this.testSuite.remove(index);
    }
    
 

    /**
     * Remove the specified collection of testSuite
     * @return true if this list changed as a result of the call 
     */
    
    @Override
    public boolean removeAll(Collection<?> arg0) {
        return this.testSuite.removeAll(arg0);
    }
   
   /**
    * 
    * Is a complementar of removeAll
    */
    @Override
    public boolean retainAll(Collection<?> arg0) {
        return this.testSuite.retainAll(arg0);
    }

    /**
     * Return size of testSuite
     */
    
    @Override
    public int size() {
        return this.testSuite.size();
    }

    
    /**
     * 
     *	Return an array of testeCases
     * 
     * @return an array containing all of the testeCases in this list in proper sequence
     */
    @Override
    public Object[] toArray() {
        return this.testSuite.toArray();
    }

    
    /**
     * 
     * Return an array containing all testCases
     */
    
    @Override
    public <T> T[] toArray(T[] arg0) {
        return this.toArray(arg0);
    }
    
    
    /**
     * Return this testSuite
     * @return testSuite
     */
	public List<TestCase> getTestSuite() {
		return testSuite;
	}
    
	/**
	 * Return a string with all testCases
	 * ex: "a(DEFAULT)-b(DEFAULT)-c(DEFAULT)-d(DEFAULT)-
	 *      a(DEFAULT)-b(DEFAULT)-g(DEFAULT)-h(DEFAULT)-"
	 *
	 * 
	 */
	
    @Override
    public String toString() {
    	String eol = System.getProperty("line.separator");
    	StringBuffer s= new StringBuffer();
//    	for(TestCase t : this.testSuite){
//    		System.out.println(t);
//    		
//    	}
    	for(TestCase t : this.testSuite){
    		s.append(t);
    		s.append(eol);
    	}
    	return s.toString();
    }
    
    
	/**
	 * Retrieve a test case in the suite in the specified index.
	 * @return A test case in the suite in the specified index.
	 */
	public TestCase get(int index) {
		return testSuite.get(index);
	}
    


    //TODO  ISSO AQUI FUNCIONA???????????????
	@Override
	public boolean remove(Object o) {
		if(o instanceof TestCase){
			TestCase testeCase = (TestCase) o;
			this.testSuite.remove(testeCase);
		}
		return false;
	}
	
	
	/**
	 * Retrieve a clone from this test suite
	 */
	public TestSuite clone() {
		TestSuite newTS = new TestSuite();
		for(TestCase t: this.getTestSuite()){
			newTS.add(t.clone());
		}
		return newTS;
	}
	
	
//  public static void main(String[] args) {
//		TestSuite t = new TestSuite();
//		
//		t.get(0);
//	}
}